home *** CD-ROM | disk | FTP | other *** search
Text File | 1998-09-06 | 6.6 KB | 346 lines | [TEXT/CWIE] |
- // MainWindow.cp
-
- #include <Types.h>
- #include <Quickdraw.h>
- #include <Controls.h>
- #include <Dialogs.h>
- #include <Events.h>
- #include <Lists.h>
- #include <Menus.h>
- #include <Resources.h>
- #include <Sound.h>
- #include <TextEdit.h>
- #include <ToolUtils.h>
- #include <Appearance.h>
-
- #include "Globals.h"
- #include "ResourceDefs.h"
- #include "DoScrap.h"
- #include "Miscellany.h"
- #include "Scrolling.h"
- #include "ControlUtils.h"
- #include "DDocData.h"
- #include "TemperatureEngine.h"
- #include "TemperatureDoc.h"
-
- #include "MainWindow.h"
-
-
- //----------
- void MainWindow::Create (
- AMDoc* inDoc,
- DDocData* inData)
- {
- MainWindow* winObj = new MainWindow;
-
- if (winObj != nil) {
- winObj->Open (inDoc);
- winObj->ConnectToData (inData);
- }
- }
-
- //----------
- MainWindow::MainWindow ()
- {
- }
-
- //----------
- MainWindow::~MainWindow ()
- {
- }
-
- //----------
- TemperatureEngine* MainWindow::GetEngine ()
- {
- return (TemperatureEngine*) mDoc->mEngine;
- }
-
- //----------
- void MainWindow::Open (
- AMDoc* inDoc)
- {
- WindowPtr window;
- Handle wftb;
-
- mDoc = inDoc;
-
- window = GetNewCWindow (WIND_MainWindow, nil, (WindowPtr) -1L);
- if (mDoc->mEngine->GetFilename () [0] != 0) {
- SetWTitle (window, mDoc->mEngine->GetFilename ());
- }
- mWindow = window;
- ((TemperatureDoc*)mDoc)->mMainWindowPtr = window;
-
- SetWindowKind (window, 'AM');
- SetWRefCon (window, (long) this);
- SetPort (window);
- SetInfo (window);
-
- wftb = ::GetResource ('Wftb', WIND_MainWindow);
-
- CreateRootControl (window, &mRootControl);
-
- vScroll = nil;
- hScroll = nil;
-
-
- mCentigradeLabel = GetNewControl (CNTL_Centigrade, window);
- SetWindowItemFont (mCentigradeLabel, wftb, 1);
- SetControlFromTEXT (mCentigradeLabel, TEXT_Centigrade);
-
- mEditCentigradeHandle = ::GetNewControl (CNTL_EditCentigrade, window);
- SetWindowItemFont (mEditCentigradeHandle, wftb, 2);
-
- mFahrenheitLabel = GetNewControl (CNTL_Fahrenheit, window);
- SetWindowItemFont (mFahrenheitLabel, wftb, 3);
- SetControlFromTEXT (mFahrenheitLabel, TEXT_Fahrenheit);
-
- mEditFahrenheitHandle = ::GetNewControl (CNTL_EditFahrenheit, window);
- SetWindowItemFont (mEditFahrenheitHandle, wftb, 4);
-
- mCentSliderHandle = ::GetNewControl (CNTL_CentSlider, window);
- SetWindowItemFont (mCentSliderHandle, wftb, 5);
-
- mFahrBarHandle = ::GetNewControl (CNTL_FahrBar, window);
- SetWindowItemFont (mFahrBarHandle, wftb, 6);
-
- AdvanceKeyboardFocus (window);
-
- ShowWindow (window);
- }
-
- //----------
- void MainWindow::Close ()
- {
- mData->RemoveResponder (this);
-
- ((TemperatureDoc*)mDoc)->mMainWindowPtr = nil;
- SetInfo (nil);
- HideWindow (mWindow);
- DisposeWindow (mWindow);
-
- delete this;
- }
-
- //----------
- void MainWindow::ConnectToData (
- DDocData* inData)
- {
- mData = inData;
- mData->AddResponder (this);
-
- SetControlTextValue (mEditCentigradeHandle, mData->GetCentigrade ());
- SetControlTextValue (mEditFahrenheitHandle, mData->GetFahrenheit ());
- SetControlValue (mCentSliderHandle, mData->GetCentigrade ());
- SetControlValue (mFahrBarHandle, mData->GetFahrenheit ());
- }
-
- //----------
- void MainWindow::DataChanged (
- long inDataID)
- {
- if (inDataID == idCentigrade) {
- SetControlTextValue (mEditCentigradeHandle, mData->GetCentigrade ());
- }
- if (inDataID == idFahrenheit) {
- SetControlTextValue (mEditFahrenheitHandle, mData->GetFahrenheit ());
- }
- if (inDataID == idCentigrade) {
- SetControlValue (mCentSliderHandle, mData->GetCentigrade ());
- }
- if (inDataID == idFahrenheit) {
- SetControlValue (mFahrBarHandle, mData->GetFahrenheit ());
- }
- }
-
- //----------
- void MainWindow::Control (
- ControlHandle whichControl,
- short whichPart,
- Point where)
- {
- Rect bounds;
- short newValue;
-
- ExitCurField ();
-
- if (whichControl == mEditCentigradeHandle) {
- HandleEditClick (mEditCentigradeHandle, where);
- }
- if (whichControl == mEditFahrenheitHandle) {
- HandleEditClick (mEditFahrenheitHandle, where);
- }
- if (whichControl == mCentSliderHandle) {
- HandleControlClick (mCentSliderHandle, where, curEvent.modifiers, nil);
- mData->SetCentigrade (GetControlValue (mCentSliderHandle));
- }
- }
-
- //----------
- void MainWindow::MouseIn (
- Point where,
- short modifiers)
- {
- Rect bounds;
-
- }
-
- //----------
- void MainWindow::ExitCurField ()
- {
- ControlHandle focus;
-
- GetKeyboardFocus (mWindow, &focus);
-
- if (focus == nil) {
- // nothing to exit
-
- } else if (focus == mEditCentigradeHandle) {
- mData->SetCentigrade (GetControlTextValue (mEditCentigradeHandle));
- } else if (focus == mEditFahrenheitHandle) {
- mData->SetFahrenheit (GetControlTextValue (mEditFahrenheitHandle));
- }
- }
-
- //----------
- void MainWindow::TypeIn (
- char ch)
- {
- ControlHandle focus;
- SInt16 keyCode;
-
- GetKeyboardFocus (mWindow, &focus);
-
- if ((ch == charEnter)
- || (ch == charReturn)) {
- ExitCurField ();
- } else if (ch == charEsc) {
- } else if (ch == charTab) {
- DoTab ((curEvent.modifiers & optionKey) != 0);
- } else if (focus != nil) {
- keyCode = (SInt16)(curEvent.message & keyCodeMask);
- HandleControlKey (focus, keyCode, ch, (SInt16)curEvent.modifiers);
- mDoc->mEngine->SetDirty ();
- } else {
- SysBeep (1);
- }
- }
-
- //----------
- void MainWindow::Resize ()
- {
- /* application-specific code to resize items in window */
- }
-
- //----------
- void MainWindow::Scroll (
- short newValue,
- short oldValue)
- {
- /* application-specific code to scroll window */
- if (gWhichScroll == vScroll) {
- } else { // horizontal
- }
- }
-
- //----------
- void MainWindow::DoUndo ()
- {
- } // DoUndo
-
- //----------
- void MainWindow::DoCut ()
- {
- TEHandle curTE = GetCurTE ();
-
- if (curTE != nil) {
- TECut (curTE);
- mDoc->mEngine->SetDirty ();
- scrapDirty = true;
- }
- } // DoCut
-
- //----------
- void MainWindow::DoCopy ()
- {
- TEHandle curTE = GetCurTE ();
-
- if (curTE != nil) {
- TECopy (curTE);
- scrapDirty = true;
- }
- } // DoCopy
-
- //----------
- void MainWindow::DoPaste ()
- {
- TEHandle curTE = GetCurTE ();
-
- if (curTE != nil) {
- TEPaste (curTE);
- mDoc->mEngine->SetDirty ();
- }
- } // DoPaste
-
- //----------
- void MainWindow::DoClear ()
- {
- TEHandle curTE = GetCurTE ();
-
- if (curTE != nil) {
- TEDelete (curTE);
- mDoc->mEngine->SetDirty ();
- }
- } // DoClear
-
- //----------
- void MainWindow::DoSelectAll ()
- {
- TEHandle curTE = GetCurTE ();
-
- if (curTE != nil) {
- TESetSelect (0, 32767, curTE);
- }
- } // DoSelectAll
-
- //----------
- void MainWindow::DoShowClipboard ()
- {
- } // DoShowClipboard
-
- //----------
- Boolean MainWindow::DoCommand (
- long inCommand)
- {
- Boolean result = true;
-
- switch (inCommand) {
- case cmdUndo:
- DoUndo ();
- break;
- case cmdCut:
- DoCut ();
- break;
- case cmdCopy:
- DoCopy ();
- break;
- case cmdPaste:
- DoPaste ();
- break;
- case cmdClear:
- DoClear ();
- break;
- case cmdSelectAll:
- DoSelectAll ();
- break;
- case cmdShowClipboard:
- DoShowClipboard ();
- break;
-
- default:
- result = false;
- } // switch
-
- return result;
- }
-